﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace WEALTH.Manager.BaseSystem
{
    public partial class MenuUpdate : BasePage
    {
        ExcuteDao menu = new ExcuteDao();
        public string strWhere = "", strSessCode = "", strSql = "", strLink = "", strMsg = "";
        public int n = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            btnUpdate.CssClass = "submit";

            strSessCode = Request.QueryString["code"].ToString().Trim();
            if (!IsPostBack)
            {
                SqlDataReader dr = null;
                try
                {
                    dr = menu.GetMenuReader(strSessCode);
                    if (dr.Read())
                    {
                        txtMenu_Code.Text = dr["Menu_Code"].ToString().Trim();
                        txtMenu_Code.Enabled = false;
                        txtMenu_Name.Text = dr["Menu_Name"].ToString().Trim();
                        txtMenu_FileName.Text = dr["Menu_FileName"].ToString().Trim();
                        //txtIco.Text = dr["Menu_Ico"].ToString().Trim();
                        txtMenu_DisplayOrder.Text = dr["Menu_DisplayOrder"].ToString().Trim();
                        rblMenu_IsUse.SelectedValue = dr["Menu_IsUse"].ToString().Trim();
                        Session["TEMP1"] = dr["Menu_Pcode"].ToString().Trim();

                    }
                    else
                    {
                        Session["Msg"] = "<script>alert('参数传递错误！');</script>";
                    }


                }
                catch (Exception ex)
                {
                    Session["Msg"] = "<script>alert('" + ex.Message.ToString() + "');</script>";
                }
                finally
                {
                    if (dr != null)
                    {
                        dr.Close();
                        dr = null;
                    }
                }
            }
        }

        //修改
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            string MenuCode = txtMenu_Code.Text.Trim();
            string MenuName = txtMenu_Name.Text.Trim();
            string PMenuCode = Session["TEMP1"].ToString().Trim();
            string FileName = txtMenu_FileName.Text.Trim();
            string Ico = "";//txtIco.Text.Trim();
            string DisplayOrder = txtMenu_DisplayOrder.Text.Trim(); ;
            string IsUse = rblMenu_IsUse.SelectedValue.ToString().Trim();


            n = menu.UpdateMenu(MenuCode, MenuName, PMenuCode, FileName, Ico, DisplayOrder, IsUse);
            if (n > 0)
            {
                Session["msg"] = "执行成功！";
                Response.Write("<script>top.window.location='../Welcome.aspx?local=BaseSystem/MenuList.aspx';</script>");
            }
            else
            {
                ShowMsg("更新失败!", 1);
                return;
            }

            return;
        }
    }
}